package com.itheima.practice;

public class QuiteSort {
    public static void main(String[] args) {
        int [] arr = {6,2,1,4,3,8,7,5,9};
        quiteSort(arr,0,arr.length-1);
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
    }

    private static void quiteSort(int[] arr, int left, int right) {
        if(right < left){
            return;
        }
        int left0 = left;
        int right0 = right;
        int baseNUmber = arr[left0];
        while (left != right){
            while (arr[right]>= baseNUmber&&right>left){
                right--;
            }
            while (arr[left]<= baseNUmber&&right>left){
                left++;
            }
            int temp = arr[left];
            arr[left] = arr[right];
            arr[right] = temp;
        }
        int temp =arr[left];
        arr[left] = arr[left0];
        arr[left0] = temp;

        quiteSort(arr,left0,left-1);
        quiteSort(arr,left+1,right0);
    }
}
